//导入request.js请求工具
import request from '@/utils/request.js'

// 管理员登录接口
export const adminLoginService = (loginData) => {
    // 使用URLSearchParams来构建表单数据
    const formData = new URLSearchParams()
    formData.append('username', loginData.username)
    formData.append('password', loginData.password)
    
    console.log('发送登录请求:', {
        username: loginData.username,
        password: loginData.password
    })
    
    return request.post('/adminUser/login', formData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}

// 获取管理员信息接口
export const getAdminInfoService = () => {
    return request.get('/adminUser/getAdminInfo')
}

// 更新管理员信息接口
export const updateAdminInfoService = (adminData) => {
    return request.put('/adminUser/updateAdminInfo', adminData, {
        headers: {
            'Content-Type': 'application/json'
        }
    })
}

// 修改管理员密码接口
export const updatePasswordService = (passwordData) => {
    return request.put('/adminUser/updatePassword', passwordData, {
        headers: {
            'Content-Type': 'application/json'
        }
    })
}

// ========================== 预约数据管理相关接口 ==========================

// 获取预约数据列表（分页查询）
export const getBookingListService = (params = {}) => {
    return request.get('/bookings/admin/getBookings', {
        params: params
    })
}

// 导出预约数据Excel
export const exportBookingsService = (params = {}) => {
    return request.get('/bookings/admin/exportBookings', {
        params: params,
        responseType: 'blob', // 用于文件下载
        timeout: 300000, // 增加超时时间到5分钟
        headers: {
            'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        }
    })
}

// 获取匿名用户列表（分页查询）
export const getAnonymousUsersService = (params = {}) => {
    return request.get('/anonymousUsers/admin/getUsers', {
        params: params
    })
}

// 导出匿名用户数据Excel
export const exportAnonymousUsersService = (params = {}) => {
    return request.get('/anonymousUsers/admin/exportUsers', {
        params: params,
        responseType: 'blob', // 用于文件下载
        timeout: 300000, // 增加超时时间到5分钟
        headers: {
            'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        }
    })
}

// 获取用户统计数据
export const getUserStatisticsService = () => {
    return request.get('/anonymousUsers/admin/statistics')
}



